{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Action 1 : 完成A+B Problem \n",
    "https://zoj.pintia.cn/problem-sets/91827364500/problems/91827364500"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "while True:\n",
    "    try:\n",
    "        a,b = input().split()\n",
    "        print(int(a) + (int(b)))\n",
    "    except:\n",
    "        break\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#Action 2 : 求2+4+6+8+...+100的求和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2550\n"
     ]
    }
   ],
   "source": [
    "sum = 0\n",
    "for i in range(2,102,2):\n",
    "    sum += i\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#Action 3 :统计全班的成绩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('张飞', 68, 65, 30) ('关羽', 95, 76, 98) ('刘备', 98, 86, 88)\n",
      " ('典韦', 90, 88, 77) ('许褚', 80, 90, 90)]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np \n",
    "studenttype = np.dtype({\n",
    "    'names' : ['name','chinese','math','english'],\n",
    "    'formats' : ['U6','i','i','i']  #注意类型详细见文档\n",
    "})\n",
    "student = np.array([\n",
    "    ('张飞',68,65,30),\n",
    "    ('关羽',95,76,98),\n",
    "    ('刘备',98,86,88),\n",
    "    ('典韦',90,88,77),\n",
    "    ('许褚',80,90,90)\n",
    "],dtype = studenttype)\n",
    "print(student)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "语文: 平均成绩:86.20，最小成绩:68.00,最大成绩:98.00,方差:120.16,标准差:10.96\n",
      "数学: 平均成绩:81.00，最小成绩:65.00,最大成绩:90.00,方差:87.20,标准差: 9.34\n",
      "英语: 平均成绩:76.60，最小成绩:30.00,最大成绩:98.00,方差:587.84,标准差:24.25\n"
     ]
    }
   ],
   "source": [
    "schinese = student['chinese']\n",
    "smath = student['math']\n",
    "senglish = student['english']\n",
    "print('语文: 平均成绩:{:.2f}，最小成绩:{:.2f},最大成绩:{:.2f},方差:{:5.2f},标准差:{:5.2f}'.format(\n",
    "    np.mean(schinese),np.min(schinese),np.max(schinese),np.var(schinese),np.std(schinese)))\n",
    "print('数学: 平均成绩:{:.2f}，最小成绩:{:.2f},最大成绩:{:.2f},方差:{:5.2f},标准差:{:5.2f}'.format(\n",
    "    np.mean(smath),np.min(smath),np.max(smath),np.var(smath),np.std(smath)))\n",
    "print('英语: 平均成绩:{:.2f}，最小成绩:{:.2f},最大成绩:{:.2f},方差:{:5.2f},标准差:{:5.2f}'.format(\n",
    "    np.mean(senglish),np.min(senglish),np.max(senglish),np.var(senglish),np.std(senglish)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "总成绩排序：\n",
      "第1名：刘备\t总成绩为：272 \n",
      "第2名：关羽\t总成绩为：269 \n",
      "第3名：许褚\t总成绩为：260 \n",
      "第4名：典韦\t总成绩为：255 \n",
      "第5名：张飞\t总成绩为：163 \n"
     ]
    }
   ],
   "source": [
    "sum_grade = {}\n",
    "for i in range(len(student)):\n",
    "    sum_grade[student[i][0]] = student[i][1] + student[i][2] + student[i][3]\n",
    "grade = sorted(sum_grade.items(), key = lambda x: x[1], reverse = True)\n",
    "\n",
    "print('总成绩排序：')\n",
    "for i in range(len(grade)):\n",
    "    print(\"第{}名：{}\\t总成绩为：{} \".format(i+1,grade[i][0],grade[i][1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
